{layout name="layout" /}

<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i>
    <a href="{:url('index/index')}"> 首页</a>
    <span class="c-gray en">&gt;</span>
    <a href="{:url('sys_user/index')}">管理员列表</a>
    <span class="c-gray en">&gt;</span>
    <a href="javascprit:;">{$data.id ? '修改' : '新增'}</a>
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);"
        title="刷新">
        <i class="Hui-iconfont">&#xe68f;</i>
    </a>
</nav>

<div class="Hui-article">
    <article class="cl pd-20">
        <form action="{:url('sys_user/save?id='.$data.id)}" method="post" class="form form-horizontal" id="form-admin-add">
            <input type="hidden" name="disVable" id="disVable" value="1">
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">
                    <span class="c-red">*</span>管理员名称：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="input-text" id="username" name="username" value="{$data.username}" autocomplete="new-password">
                </div>
                <div class="form-label col-xs-4 col-sm-4 text-l" style="text-align: left;">
                    <span class="c-red" id="span_username"></span></div>
            </div>
            {empty name="$data.id"}
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">
                    <span class="c-red">*</span>初始密码：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="password" class="input-text" id="password" name="password" value="" placeholder="初始密码, 6位及以上, 至少包括字母和数字" autocomplete="new-password">
                </div>
                <div class=" form-label col-xs-4 col-sm-4" style="text-align: left;">
                    <span class="c-red" id="span_password">* 为空时使用系统配置的默认密码</span></div>
            </div>
            {else/}
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">
                    <span class="c-red">*</span>修改密码：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="password" class="input-text" id="password" name="password" value="" placeholder="6位及以上, 至少包括字母和数字" autocomplete="new-password">
                </div>
                <div class="form-label col-xs-4 col-sm-2" style="text-align: left;">
                    <span class="c-red" id="span_password"></span></div>
            </div>
            {/empty}
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">
                    <span class="c-red">*</span>确认密码：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="password" class="input-text"  id="repassword" name="repassword" value="" placeholder="确认密码, 两次密码需一致">
                </div>
                <div class="form-label col-xs-4 col-sm-2" style="text-align: left;">
                    <span class="c-red" id="respan_password"></span></div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">
                    姓名: </label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="input-text" id="truename" name="truename" value="{$data.truename}" placeholder="姓名">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">邮箱：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="input-text" id="email" name="email" value="{$data.email}" autocomplete='email'>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">
                    <span class="c-red">*</span>角色：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <span class="select-box" style="width:150px;">
                        <select class="select" id="role_id" name="role_id">
                            {foreach $dataRole as $k=>$op}
                            <option value="{$k}" {eq name="data.role_id" value="$k"}selected{/eq}>{$op}</option>
                            {/foreach}
                        </select>
                    </span>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">备注：</label>
                <div class="formControls col-xs-8 col-sm-4">
                    <textarea id="note" name="note" cols="" rows="" class="textarea" placeholder="备注...200个字符以内" dragonfly="true"
                        onKeyUp="textarealength(this,200)">{$data.note}</textarea>
                    <p class="textarea-numberbar">
                        <em class="textarea-length">0</em>/200</p>
                </div>
            </div>
            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input class="btn btn-success radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                    <input class="btn btn-default radius" type="button" value="&nbsp;&nbsp;取消&nbsp;&nbsp;" onClick="window.history.back();">
                </div>
            </div>
        </form>
    </article>
</div>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    $(function () {
        // 密码正则验证复杂度
        $("#password").blur(function() {
            var password = $("#password").val();
            
            var res = pwdFormat6Mix(password);
            if (!res) {
                $("#span_password").html('* 密码6位及以上, 至少包括字母和数字');
                $("#disVable").val(0);
            } else {
                $("#span_password").html('');
                $("#disVable").val(1);
            }
        })

        // 确认密码
        $("#repassword").blur(function() {
            var password = $("#password").val();
            if (!isNull(password) && password != $("#repassword").val()) {
                $("#respan_password").html('* 两次密码不一致');
                $("#disVable").val(0);
            } else {
                $("#respan_password").html('');
                $("#disVable").val(1);
            }
        })

        $("#form-admin-add").submit(function () {
            if ($("#disVable").val() != 1) {
                return false;
            }
            var note = $("#note").val();
            var email = $("#email").val();
            var password = $("#password").val();

            if (!$("#username").val() || !$("#role_id").val) {
                layer.msg('用户名 or 角色 不能为空!', {
                    icon: 5,
                    time: 1000
                });
                return false;
            }
            
            if (!isNull(email) && testEmail(email) == false) {
                layer.msg('邮箱格式不正确', {
                    icon: 5,
                    time: 1000
                });
                return false;
            }

            if (getblen(note) > 200) {
                layer.msg('备注过长', {
                    icon: 5,
                    time: 1000
                });
                return false;
            }
        })
    })
</script>
<!--请在上方写此页面业务相关的脚本-->